"""
use 'while' and  'for ... in' respectively to realize 9*9 multiplication table as follows
--------------
1*1=1
2*1=2   2*2=4
...
9*1=9   9*2=18  ...  9*9=81
----------------
9*1=9   9*2=18  ...  9*9=81
...
2*1=2   2*2=4
1*1=1
--------------
1*1=1
1*2=2   2*2=4
...
1*9=9   2*9=18  ...  9*9=81
----------------
1*9=9   2*9=18  ...  9*9=81
...
1*2=2   2*2=4
1*1=1
"""

# steps：
#   1. conform the top left corner as (1,1) point of mul_tab, format='row'*'col'
#   2. output: one line by one line and a new line is needed when it's finished every time
#   3. line number as 'row'
#   4. format the output and use placeholders

print('{}{}{}'.format('= ' * 15, 'for...in (1)', '= ' * 15))
for row in range(1, 10):
    for col in range(1, row + 1):
        print('{}*{}={:<4}'.format(row, col, row * col), end='')
    print('')
print('- ' * 37)
print('')

print('{}{}{}'.format('= ' * 15, 'for...in (2)', '= ' * 15))
for row1 in range(9, 0, -1):
    for col1 in range(1, row1 + 1):
        print('{}*{}={:<4}'.format(row1, col1, row1 * col1), end='')
    print('')
print('- ' * 37)
print('')

print('{}{}{}'.format('= ' * 15, 'for...in (3)', '= ' * 15))
for row2 in range(1, 10):
    for col2 in range(1, row2 + 1):
        print('{}*{}={:<4}'.format(col2, row2, col2 * row2), end='')
    print('')
print('- ' * 37)
print('')

print('{}{}{}'.format('= ' * 15, 'for...in (4)', '= ' * 15))
for row3 in range(9, 0, -1):
    for col3 in range(1, row3 + 1):
        print('{}*{}={:<4}'.format(col3, row3, col3 * row3), end='')
    print('')
print('- ' * 37)
print('')

print('{}{}{}'.format('= ' * 17, 'while(1)', '= ' * 17))
row4 = col4 = 1
while row4 < 10:
    while col4 < row4+1:
        print('{}*{}={:<4}'.format(row4, col4, row4 * col4), end='')
        col4 += 1
    print('')
    row4 += 1
    col4 = 1
print('- ' * 37)
print('')

print('{}{}{}'.format('= ' * 17, 'while(2)', '= ' * 17))
row5 = col5 = 1
while row5 < 10:
    while col5 < 11-row5:
        print('{}*{}={:<4}'.format(row5, col5, row5 * col5), end='')
        col5 += 1
    print('')
    row5 += 1
    col5 = 1
print('- ' * 37)
print('')

print('{}{}{}'.format('= ' * 17, 'while(3)', '= ' * 17))
row6 = col6 = 1
while row6 < 10:
    while col6 < row6+1:
        print('{}*{}={:<4}'.format(col6, row6, col6 * row6), end='')
        col6 += 1
    print('')
    row6 += 1
    col6 = 1
print('- ' * 37)
print('')

print('{}{}{}'.format('= ' * 17, 'while(4)', '= ' * 17))
row7 = col7 = 1
while row7 < 10:
    while col7 < 11-row7:
        print('{}*{}={:<4}'.format(col7, row7, col7 * row7), end='')
        col7 += 1
    print('')
    row7 += 1
    col7 = 1
print('- ' * 37)
print('')
